package tod141.medlemsliste.controller;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import tod141.medlemsliste.model.Klient;
import tod141.medlemsliste.skjemadata.NyKlient;
import tod141.medlemsliste.utilities.RequestException;
import tod141.medlemsliste.utilities.ServletUtilities;

@WebServlet("/KlientStatistikk")
public class KlientStatistikk extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String adresse="/WEB-INF/feilBruk.jsp";
	    RequestDispatcher dispatcher = request.getRequestDispatcher(adresse);
	    dispatcher.forward(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		NyKlient klientSkjemaData = new NyKlient();
		try{
			BeanUtils.populate(klientSkjemaData, request.getParameterMap());
			Klient klient = klientSkjemaData.getKlient();
			if(klient == null) 
				throw new RequestException("Data lost in void -.-");
		
			ServletUtilities.sendResponse(response, true);
		}catch(Exception e){
			ServletUtilities.sendResponse(response, false);
		}
	}

}
